/**
 * 
 */
package com.effectiv.gooruda.rest.api.controller;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.effectiv.gooruda.domain.CloudQueue;
import com.effectiv.gooruda.rest.api.operation.QueueOperations;

/**
 * @author Dhrubo
 * 
 */
//@Controller
@RequestMapping("/api/cq")
@Slf4j
public class QueueController implements QueueOperations {

	@Autowired
	@Qualifier("queueServiceImpl")
	private QueueOperations operations;

	// UC : 001
	@Override
	@RequestMapping(value = "/queues", method = RequestMethod.GET)
	public @ResponseBody
	List<CloudQueue> findAll(
			@RequestParam(value = "page", required = false, defaultValue = "-1") int pageNo,
			@RequestParam(value = "size", required = false, defaultValue = "-1") int pageSize) {

		log.debug("pageNo = {}", pageNo);
		log.debug("pageSize = {}", pageSize);

		return operations.findAll(pageNo, pageSize);
	}

	// UC : 002
	@Override
	@RequestMapping(value = "/queue/{queueName}", method = RequestMethod.GET)
	public @ResponseBody
	CloudQueue findByName(@PathVariable("queueName") String queueName) {
		return operations.findByName(queueName);
	}

	// UC : 003
	@Override
	@RequestMapping(value = "/queue/{queueName}", method = RequestMethod.DELETE)
	public void delete(@PathVariable("queueName") String queueName) {
		operations.delete(queueName);

	}

	// UC : 004
	@RequestMapping(value = "/queue/{queueName}", method = RequestMethod.POST)
	public void create(@PathVariable("queueName") String queueName) {
		operations.create(queueName);
	}
	
	// UC : 005
	@RequestMapping(value = "/queue/{queueName}/purge", method = RequestMethod.POST)
	@Override
	public void purge(@PathVariable("queueName") String queueName) {
		operations.purge(queueName);
		
	}
	
	
}
